package interfaceCusService;

import interfaceWorker.WorkerGui;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.UIManager;
import javax.swing.border.Border;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableModel;

public class ComplaintTable extends JPanel implements ActionListener {
	
	private JButton btnMainMenu;
	private JTable custable;
	private String[] columns = {"Name","CID","CarId","Date"};
	private Dimension wfs;
	private CusServiceFrame csfg;
	String[] data;
	private DefaultTableModel tm;
	private JScrollPane scrollPane;
	private JButton btnBackToMenu,btnAnswer;
	private int r;
	private ComplaintTable ct;
	private String temp="";
	
	public ComplaintTable(Dimension fz, CusServiceFrame wfg){
		
		wfs=fz;
		csfg=wfg;
		ct=this;
		this.setSize(wfs);
		this.setLayout(null);
		
		tm = new DefaultTableModel(null, columns);
		custable = new JTable(tm){
			public boolean isCellEditable(int row, int column){
		        return false; 
		}
		};
		//custable.isCellEditable(0, 0);
	    scrollPane = new JScrollPane(custable);
	    scrollPane.setBounds(30, 0, 430, 220);
	    /*headerBorder = UIManager.getBorder("TableHeader.cellBorder");
	    headerLabel1 = new JLabel(columns[0], JLabel.CENTER);
	    headerLabel1.setBorder(headerBorder);
	    headerLabel2 = new JLabel(columns[1], JLabel.CENTER);
	    headerLabel2.setBorder(headerBorder);
	    renderer = new TableCellRenderer();*/
	    
		/*temp = getModel();
		tm = (DefaultTableModel) temp;*/
		for (int i = 0; i < 1; i++)
        {
            tm.addRow(new Object[]{});
        }
		Calendar c= GregorianCalendar.getInstance();
		tm.setValueAt("adi", 0, 0);
		tm.setValueAt("132", 0, 1);
		tm.setValueAt(6846, 0, 2);
		tm.setValueAt(c.getTime(), 0, 3);
		
		btnBackToMenu = new JButton("Back To Menu");
		btnBackToMenu.setBounds(45, 250, 115, 25);
		this.add(btnBackToMenu);
		btnBackToMenu.addActionListener(this);
		
		btnAnswer = new JButton("Answer Complaint");
		btnAnswer.setBounds(300, 250, 150, 25);
		this.add(btnAnswer);
		btnAnswer.addActionListener(this);
		
		this.add(scrollPane,BorderLayout.CENTER);
		//this.add(custable,BorderLayout.CENTER);
		this.setVisible(true);
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		if(e.getSource() == btnBackToMenu)
        {
        	//removeAll();
	        add(new CusServiceGui(wfs,csfg));
	        validate();
	        repaint();
        }
		
		if(e.getSource() == btnAnswer)
        {
			r=custable.getSelectedRow();
			data=new String[4];
			for(int i=0;i<4;i++)
				data[i]=(String)tm.getValueAt(r, i).toString();
			
        	//removeAll();
			//this.setVisible(false);
	        csfg.setContentPane(new AnswerComplaintPanel(wfs,csfg,data,ct));
	        validate();
	        repaint();

        }
	}
	
	public void removerRow()
	{
		tm.removeRow(r);
	}

}
